package com.ybkj.o2o.mc.service.impl;


import com.ybkj.o2o.mc.common.query.AccountQuery;
import com.ybkj.o2o.mc.entity.PassengerAccount;
import com.ybkj.o2o.mc.mapper.PassengerAccountMapper;
import com.ybkj.o2o.mc.service.PassengerAccountService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shine on 15/8/19.
 */
@Service
public class DefaultPassengerAccountService implements PassengerAccountService {

  @Autowired
  private PassengerAccountMapper passengerAccountMapper;


  @Override
  public List<PassengerAccount> findPassengerAccount(Long passengerId, int offset, int rows) {

    return passengerAccountMapper.selectByPassengerForPage(passengerId, offset, rows);
  }

  @Override
  public List<PassengerAccount> findPassengerAccount(Long orderId, String payType, String appKey) {

    return passengerAccountMapper.selectByOrderAndPayType(orderId, payType, appKey);
  }

  @Override
  public long countPassengerAccount(Long passengerId) {

    return passengerAccountMapper.countByPassenger(passengerId);
  }

  @Override
  public PassengerAccount fetch(Long accountId, Long passengerId) {

    return passengerAccountMapper.selectByIdAndPassenger(accountId, passengerId);
  }

  @Override
  public int update(PassengerAccount passengerAccount) {

    passengerAccount.setUpdated(new Date());

    return passengerAccountMapper.updateByPrimaryKey(passengerAccount);
  }


  @Override
  public List<PassengerAccount> findAccountDetail(AccountQuery accountQuery) {


    return passengerAccountMapper.selectByAccountQuery(accountQuery);
  }

  @Override
  public Long countAccountDetail(AccountQuery accountQuery) {

    return passengerAccountMapper.countByAccountQuery(accountQuery);

  }


  @Override
  public double sumAccount(AccountQuery accountQuery) {

    return passengerAccountMapper.sumAccount(accountQuery);
  }

  @Override
  public int insert(PassengerAccount passengerAccount) {
    passengerAccount.setVersion(1);

    return passengerAccountMapper.insert(passengerAccount);
  }
}
